package com.whsxt.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import reactor.core.publisher.Mono;

//限流的配置
@Configuration
public class RequestRateLimitConfig {
    //根据ip限流
    @Bean
    @Primary
    public KeyResolver ipAddrKeyResolver(){
        return exchange -> Mono.just(exchange.getRequest().getHeaders().getHost().getHostString());
    }
    //根据api(请求路径)限流
    @Bean
    public KeyResolver apiKeyResolver(){
        return exchange -> Mono.just(exchange.getRequest().getURI().getPath());
    }
}
